﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Xml;
using uComponents.Core.DataTypes.MultiUrlPicker.Dto;
using umbraco.MacroEngines;
using umbraco.MacroEngines.Library;
using System.Collections;

namespace uComponents.RazorModels.MultiUrlPicker
{
    [RazorDataTypeModel("29F9301C-31F8-437D-B6B5-897C1CAFE586")]
    public class MultiUrlPickerModelBinder : IRazorDataTypeModel
    {
        public bool Init(int CurrentNodeId, string PropertyData, out object instance)
        {
            RazorMultiUrlPickerState state = null;

            if (!string.IsNullOrEmpty(PropertyData))
            {
                MultiUrlPickerState innerState = MultiUrlPickerState.Deserialize(PropertyData);
                state = new RazorMultiUrlPickerState()
                {
                    Items = innerState.Items
                };
            }

            instance = state;

            return true;
        }
    }
}
